<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
	<title>CKEDITOR.htmlParser.fragment</title>
	<link rel="stylesheet" type="text/css" href="../../test.css" />
	<script type="text/javascript" src="../../../ckeditor.js"></script>
	<script type="text/javascript" src="../../test.js"></script>
	<script type="text/javascript">
	//<![CDATA[

var tc;

CKEDITOR.test.addTestCase( tc = (function()
{
	// Local reference to the "assert" object.
	var assert = CKEDITOR.test.assert;

	function testParser( input, expected )
	{
		var fragment = CKEDITOR.htmlParser.fragment.fromHtml( input, 'p' ),
			writer = new CKEDITOR.htmlParser.basicWriter();

		fragment.writeHtml( writer );

		assert.areSame( expected, writer.getHtml( true ) );
	}

	return {
		test_fromHtml_1 : function()
		{
			var fragment = CKEDITOR.htmlParser.fragment.fromHtml( '<p>Test</p>' );

			assert.areSame( 1, fragment.children.length, 'Wrong size' );
			assert.areSame( CKEDITOR.NODE_ELEMENT, fragment.children[0].type, 'Wrong child type' );
			assert.areSame( 'p', fragment.children[0].name, 'Wrong child name' );
		},

		test_parser_1 : function()
		{
			testParser(	'<table><tr><td>1</td><p><b>2</b> Test</p><td>3</td></tr></table>',
						'<p><b>2</b> Test</p><table><tr><td>1</td><td>3</td></tr></table>' );
		},

		test_parser_2 : function()
		{
			testParser(	'<b><table><tr><td>1</td><td>2</td></tr></table></b>',
						'<table><tr><td><b>1</b></td><td><b>2</b></td></tr></table>' );
		},

		test_parser_3_1 : function()
		{
			testParser(	'<b><i>Table:<table><tr><td>1</td><td>2</td></tr></table></i></b>',
						'<p><b><i>Table:</i></b></p><table><tr><td><b><i>1</i></b></td><td><b><i>2</i></b></td></tr></table>' );
		},

		test_parser_3_2 : function()
		{
			testParser(	'<b><i><table><tr><td>1</td><td>2</td></tr></table>Table</i></b>',
						'<table><tr><td><b><i>1</i></b></td><td><b><i>2</i></b></td></tr></table><p><b><i>Table</i></b></p>' );
		},

		test_parser_4 : function()
		{
			testParser(	'<b><i>Test',
						'<p><b><i>Test</i></b></p>' );
		},

		test_parser_5 : function()
		{
			testParser(	'<p>Para 1<p>Para 2<p>Para 3',
						'<p>Para 1</p><p>Para 2</p><p>Para 3</p>' );
		},

		test_parser_6 : function()
		{
			testParser(	'<b>A</b><i>B</i>',
						'<p><b>A</b><i>B</i></p>' );
		},

		test_parser_7 : function()
		{
			testParser(	'<p>Para 1<hr>Para 2<h1>Para 3',
						'<p>Para 1</p><hr /><p>Para 2</p><h1>Para 3</h1>' );
		},

		/**
		 * Test remove empty inline element.
		 */
		test_parser_8 : function()
		{
			testParser(	'<p><b></b>text</p>',
						'<p>text</p>' );
		},

		/**
		 *  Test remove multiple empty inline elements.
		 */
		test_parser_8_2 : function()
		{
			testParser(	'<p><b><i></b></i>text</p>',
						'<p>text</p>' );
		},

		/**
		 * Test fixing malformed inline element closing.
		 */
		test_parser_9 : function()
		{
			testParser(	'<p><b>bold<i>ita</b>lic</i></p>',
						'<p><b>bold<i>ita</i></b><i>lic</i></p>' );
		},

		test_ticket_10 : function()
		{
			testParser(	'<table><tbody><tr><td>A<b></b></td></tr></tbody></table>',
						'<table><tbody><tr><td>A</td></tr></tbody></table>' );
		},

		/**
		 *  Test fixing paragraph inside table row.
		 */
		test_ticket_3195 : function()
		{
			testParser(	'<table><tr><td>1</td><p>2</p><td>3</td></tr></table>',
						'<p>2</p><table><tr><td>1</td><td>3</td></tr></table>' );
		},

		/**
		 *  Test fixing paragraph inside list.
		 */
		test_ticket_3195_2 : function()
		{
			testParser(	'<ul><li>1</li><p>2</p><li>3</li></ul>',
						'<p>2</p><ul><li>1</li><li>3</li></ul>' );
		},

		/**
		 *  Test fixing 'div' inside paragraph.
		 */
		test_ticket_3195_3 : function()
		{
			testParser(	'<p>1<div>2</div><span>3</span></p>',
						'<p>1</p><div>2</div><p><span>3</span></p>' );
		},

		test_ticket_3441 : function()
		{
			testParser(	'<p><b>Test</b></p><script type="test">var a = "<A Href=xxx>Testing</ A>";\nGo();<\/script>',
						'<p><b>Test</b></p><script type="test">var a = "<A Href=xxx>Testing</ A>";\nGo();<\/script>' );
		},

		test_ticket_3585 : function()
		{
			testParser(	'<p><br />\t\r\n</p>',
						'<p><br /></p>' );
		},

		test_ticket_3585_1 : function()
		{
			testParser(	'<p><br />text\t\r\n</p>',
						'<p><br />text</p>' );
		},

		test_ticket_3585_2 : function()
		{
			testParser(	'<b>inline </b>\n<p>paragraph\t\r\n</p>\t\r\n',
						'<p><b>inline </b></p><p>paragraph</p>' );
		},

		test_ticket_3744 : function()
		{
			testParser(	'<div><b><font><span>A</font></span></b></div><div>X</div>',
						'<div><b><font><span>A</span></font></b></div><div>X</div>' );
		},

		name : document.title
	};
})() );

// Uncomment the following to run a single test.
// window.onload = tc.test_ticket_3585_2;

	//]]>
	</script>
</head>
<body>
</body>
</html>
